define(['jquery', 'bootstrap', 'backend', 'form', 'table'], function ($, undefined, Backend, Form, Table) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'customer/index/index',
                    add_url: 'customer/index/add',
                    edit_url: 'customer/index/edit',
                    del_url: 'customer/index/del',
                    multi_url: 'customer/index/multi',
                    detail_url: 'customer/index/detail',
                    table: 'index'
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                sortName: 'id',
                showExport:false,
                columns: [
                    [
                        {field: 'state', checkbox: true},
                        {field: 'id', title: __('ID'),operate: false,sortable: true},
                        {field: 'name', title: '客户名称', sortable: false,operate: 'like'},
                        {field: 'code', title: '客户编码', sortable: false,operate: 'like'},
                        {field: 'status', title: __("Status"), searchList: {"1":"正常","-1":"异常"}, custom:{"1":"green","-1":"red"},formatter: Table.api.formatter.status},
                        {
                            field: 'createtime',
                            title: __('Createtime'),
                            formatter: Table.api.formatter.datetime,
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            sortable: true,
                            width: 150
                        },
                        {
                            field: 'updatetime',
                            title: __('Updatetime'),
                            formatter: Table.api.formatter.datetime,
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            sortable: true,
                            width: 150
                        },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            // buttons: [
                            //     {
                            //         name: 'detail',
                            //         text: __('detail'),
                            //         title: __('detail'),
                            //         classname: 'btn btn-xs btn-success',
                            //         url: $.fn.bootstrapTable.defaults.extend.detail_url,
                            //     },
                            // ],
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ],
            });


            // 为表格绑定事件
            Table.api.bindevent(table);

        },
        add: function () {

            $(document).on("fa.event.appendfieldlist", ".btn-append", function(){
                Form.events.selectpage($("#product_json"));
            });

            Controller.api.bindevent();
        },
        edit: function () {
            $(document).on("fa.event.appendfieldlist", ".btn-append", function(){
                Form.events.selectpage($("#product_json"));
            });

            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },

        },

    };


    return Controller;
});
